﻿import QtQuick 2.15
import QtQuick.Controls 2.15

Item {
    width: loginWindow.width / 2
    height: loginWindow.height * 2 / 3
    Item{
        id:backGround
        anchors.fill: parent
    }

    Rectangle{
        anchors.fill: backGround
        color: "lightsteelblue"
    }



    /////////////PLC 连接参数///////////////

    Rectangle{
        width: backGround.width * 0.3
        height: 1
        anchors.left: backGround.left
        anchors.leftMargin: 10
        anchors.verticalCenter: plcTitle.verticalCenter
    }

    Rectangle{
        width: backGround.width * 0.3
        height: 1
        anchors.right: backGround.right
        anchors.rightMargin: 10
        anchors.verticalCenter: plcTitle.verticalCenter
    }

    Label{
        id:plcTitle
        anchors.horizontalCenter: backGround.horizontalCenter
        anchors.top: backGround.top
        anchors.topMargin: 50
        font.pixelSize: 30
        text:"PLC连接属性"
    }

    Label{
        anchors.right: idAddr_rec.left
        anchors.rightMargin: 10
        anchors.verticalCenter: idAddr_rec.verticalCenter
        font.pixelSize: 20
        text:"IP地址:"
    }

    Rectangle{
        id:idAddr_rec
        width: 300
        height: 40
        anchors.horizontalCenter: backGround.horizontalCenter
        anchors.horizontalCenterOffset: 30
        anchors.top: backGround.top
        anchors.topMargin: 100
        clip: true
        border.width: 1

        Text{
            id:ipAddr
            anchors.centerIn: parent
            font.pixelSize: 30
            verticalAlignment: Text.AlignVCenter
            horizontalAlignment: Text.horizontalAlignment
        }

        TextInput{      // IP地址输入框
            id:ipAddrInput
            visible: false
            anchors.centerIn: parent
            font.pixelSize: 30
            selectByMouse: true
            // @disable-check M16
            verticalAlignment: Text.AlignVCenter
            horizontalAlignment: Text.horizontalAlignment
            cursorVisible: true
            text: ipAddr.text
            // @disable-check M16
            onEditingFinished:{
                ipAddr.text = ipAddrInput.text
                ipAddrInput.visible = false
                ipAddr.visible = true
            }

        }

        MouseArea{
            anchors.fill: parent
            acceptedButtons: Qt.LeftButton
            // @disable-check M16
            propagateComposedEvents: true

            onClicked: {
                mouse.accepted = false
                ipAddr.visible = false
                ipAddrInput.visible = true
                ipAddrInput.forceActiveFocus();
            }
        }

    }

    Label{
        anchors.right: portNumber_rec.left
        anchors.rightMargin: 10
        anchors.verticalCenter: portNumber_rec.verticalCenter
        font.pixelSize: 20
        text:"端口号:"
    }


    Rectangle{
        id:portNumber_rec
        width: 300
        height: 40
        anchors.horizontalCenter: backGround.horizontalCenter
        anchors.horizontalCenterOffset: 30
        anchors.top: backGround.top
        anchors.topMargin: 160
        clip: true
        border.width: 1

        Text{
            id:portNumber
            anchors.centerIn: parent
            font.pixelSize: 30
            verticalAlignment: Text.AlignVCenter
            horizontalAlignment: Text.horizontalAlignment
        }

        TextInput{      // 端口号输入框
            id:portNumberInput
            visible: false
            anchors.centerIn: parent
            font.pixelSize: 30
            selectByMouse: true
            // @disable-check M16
            verticalAlignment: Text.AlignVCenter
            horizontalAlignment: Text.horizontalAlignment
            // font.pixelSize: textPixsize
            cursorVisible: true
            text: portNumber.text
            // @disable-check M16
            onEditingFinished:{
                portNumber.text = portNumberInput.text
                portNumberInput.visible = false
                portNumber.visible = true
            }

        }

        MouseArea{
            anchors.fill: parent
            acceptedButtons: Qt.LeftButton
            // @disable-check M16
            propagateComposedEvents: true

            onClicked: {
                mouse.accepted = false
                portNumber.visible = false
                portNumberInput.visible = true
                portNumberInput.forceActiveFocus();
            }
        }
    }



    ////////////////////打印机 连接属性////////////////

    Rectangle{
        width: backGround.width * 0.2
        height: 1
        anchors.left: backGround.left
        anchors.leftMargin: 10
        anchors.verticalCenter: printerTitle.verticalCenter
    }

    Rectangle{
        width: backGround.width * 0.2
        height: 1
        anchors.right: backGround.right
        anchors.rightMargin: 10
        anchors.verticalCenter: printerTitle.verticalCenter
    }


    Label{
        id:printerTitle
        anchors.horizontalCenter: backGround.horizontalCenter
        anchors.top: backGround.top
        anchors.topMargin: 250
        font.pixelSize: 30
        text:"打印机连接属性"
    }

    Column{
        anchors.horizontalCenter: parent.horizontalCenter
        anchors.top: printerTitle.bottom
        anchors.topMargin: 30

        Item{
            width: 500
            height: 60

            Label{
                anchors.verticalCenter: printerPortName.verticalCenter
                anchors.right: printerPortName.left
                anchors.rightMargin: 10
                font.pixelSize: 20
                text:"打印机-端口号"
            }

            ComboBox{
                id:printerPortName
                width: 300
                anchors.right: parent.right
                anchors.rightMargin: 20
                anchors.verticalCenter: parent.verticalCenter
                model: Cpp_Connect.serialInfo

                onPressedChanged: {
                    if(pressed === true)
                    {
                        console.log("打印机刷新串口信息")
                        Cpp_Connect.scanAvailableInfo()
                    }
                }
            }
        }
        Item{
            width: 500
            height: 60

            Label{
                anchors.verticalCenter: printerBaudRate.verticalCenter
                anchors.right: printerBaudRate.left
                anchors.rightMargin: 10
                font.pixelSize: 20
                text:"打印机-波特率"
            }

            ComboBox{
                id:printerBaudRate
                width: 300
                anchors.right: parent.right
                anchors.rightMargin: 20
                anchors.verticalCenter: parent.verticalCenter
                model:["9600","19200","39400","57600","115200"]
            }
        }
        Item{
            width: 500
            height: 60

            Label{
                anchors.verticalCenter: printerDataBite.verticalCenter
                anchors.right: printerDataBite.left
                anchors.rightMargin: 10
                font.pixelSize: 20
                text:"打印机-数据位"
            }

            ComboBox{
                id:printerDataBite
                width: 300
                anchors.right: parent.right
                anchors.rightMargin: 20
                anchors.verticalCenter: parent.verticalCenter
                currentIndex: 3
                model:["5","6","7","8"]
            }
        }
        Item{
            width: 500
            height: 60

            Label{
                anchors.verticalCenter: printerParity.verticalCenter
                anchors.right: printerParity.left
                anchors.rightMargin: 10
                font.pixelSize: 20
                text:"打印机-校验位"
            }

            ComboBox{
                id:printerParity
                width: 300
                anchors.right: parent.right
                anchors.rightMargin: 20
                anchors.verticalCenter: parent.verticalCenter
                model:["None","Even","Odd","Mark","Space"]
            }
        }
        Item{
            width: 500
            height: 60

            Label{
                anchors.verticalCenter: printerStopBite.verticalCenter
                anchors.right: printerStopBite.left
                anchors.rightMargin: 10
                font.pixelSize: 20
                text:"打印机-停止位"
            }

            ComboBox{
                id:printerStopBite
                width: 300
                anchors.right: parent.right
                anchors.rightMargin: 20
                anchors.verticalCenter: parent.verticalCenter
                model:["1","1.5","2"]
            }
        }
    }
    /////////////////////////////////////////////////


    ////////////////////扫码枪 连接属性////////////////
    Rectangle{
        width: backGround.width * 0.2
        height: 1
        anchors.left: backGround.left
        anchors.leftMargin: 10
        anchors.verticalCenter: scannerTitle.verticalCenter
    }

    Rectangle{
        width: backGround.width * 0.2
        height: 1
        anchors.right: backGround.right
        anchors.rightMargin: 10
        anchors.verticalCenter: scannerTitle.verticalCenter
    }


    Label{
        id:scannerTitle
        anchors.horizontalCenter: backGround.horizontalCenter
        anchors.top: backGround.top
        anchors.topMargin: 690
        font.pixelSize: 30
        text:"扫码枪连接属性"
    }
    Column{
        anchors.horizontalCenter: parent.horizontalCenter
        anchors.top: scannerTitle.bottom
        anchors.topMargin: 30

        Item{
            width: 500
            height: 60

            Label{
                anchors.verticalCenter: scannerPortName.verticalCenter
                anchors.right: scannerPortName.left
                anchors.rightMargin: 10
                font.pixelSize: 20
                text:"扫码枪-端口号"
            }

            ComboBox{
                id:scannerPortName
                width: 300
                anchors.right: parent.right
                anchors.rightMargin: 20
                anchors.verticalCenter: parent.verticalCenter
                model: Cpp_Connect.serialInfo

                onPressedChanged: {
                    if(pressed === true)
                    {
                        console.log("扫码枪刷新串口信息")
                        Cpp_Connect.scanAvailableInfo()
                    }
                }
            }
        }
        Item{
            width: 500
            height: 60

            Label{
                anchors.verticalCenter: scannerBaudRate.verticalCenter
                anchors.right: scannerBaudRate.left
                anchors.rightMargin: 10
                font.pixelSize: 20
                text:"扫码枪-波特率"
            }

            ComboBox{
                id:scannerBaudRate
                width: 300
                anchors.right: parent.right
                anchors.rightMargin: 20
                anchors.verticalCenter: parent.verticalCenter
                model:["9600","19200","39400","57600","115200"]
            }
        }
        Item{
            width: 500
            height: 60

            Label{
                anchors.verticalCenter: scannerDataBite.verticalCenter
                anchors.right: scannerDataBite.left
                anchors.rightMargin: 10
                font.pixelSize: 20
                text:"扫码枪-数据位"
            }

            ComboBox{
                id:scannerDataBite
                width: 300
                anchors.right: parent.right
                anchors.rightMargin: 20
                anchors.verticalCenter: parent.verticalCenter
                currentIndex: 3
                model:["5","6","7","8"]
            }
        }
        Item{
            width: 500
            height: 60

            Label{
                anchors.verticalCenter: scannerParity.verticalCenter
                anchors.right: scannerParity.left
                anchors.rightMargin: 10
                font.pixelSize: 20
                text:"扫码枪-校验位"
            }

            ComboBox{
                id:scannerParity
                width: 300
                anchors.right: parent.right
                anchors.rightMargin: 20
                anchors.verticalCenter: parent.verticalCenter
                model:["None","Even","Odd","Mark","Space"]
            }
        }
        Item{
            width: 500
            height: 60

            Label{
                anchors.verticalCenter: scannerStopBite.verticalCenter
                anchors.right: scannerStopBite.left
                anchors.rightMargin: 10
                font.pixelSize: 20
                text:"扫码枪-停止位"
            }

            ComboBox{
                id:scannerStopBite
                width: 300
                anchors.right: parent.right
                anchors.rightMargin: 20
                anchors.verticalCenter: parent.verticalCenter
                model:["1","1.5","2"]
            }
        }
    }




    /////////////////////////////////////////////////


    Rectangle{
        id:linkAndSaveBtn
        objectName: "linkAndSaveBtn"
        anchors.bottom: backGround.bottom
        anchors.bottomMargin: 40
        anchors.horizontalCenter: backGround.horizontalCenter
        width: 300
        height: 80
        radius: 10
        border.width: 1

        MouseArea{
            anchors.fill: parent
            onPressed: {
                parent.color = "lightgray"                                
            }

            onReleased: {
                parent.color = "white"
                Cpp_Connect.getParamaterFromQML(ipAddr.text,portNumber.text,
                                               printerPortName.currentText,printerBaudRate.currentText,printerDataBite.currentText,printerParity.currentText,printerStopBite.currentText,
                                               scannerPortName.currentText,scannerBaudRate.currentText,scannerDataBite.currentText,scannerParity.currentText,scannerStopBite.currentText)
            }
        }

        Text{
            anchors.centerIn: parent
            font.pixelSize: 30
            font.bold: true
            text:"连接并保存数据"
        }
    }





}
